package zhengyanze.com.aipoemmax.guide.fragment.filter;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import zhengyanze.com.aipoemmax.R;
import zhengyanze.com.aipoemmax.guide.Constant;
import zhengyanze.com.aipoemmax.guide.activity.MingActivity;
import zhengyanze.com.aipoemmax.guide.adapter.LeiXingAdapter;
import zhengyanze.com.aipoemmax.guide.bean.LeiXingBean;
import zhengyanze.com.aipoemmax.guide.utils.LogUtils;
import zhengyanze.com.aipoemmax.guide.utils.TypefaceUtil;

import static zhengyanze.com.aipoemmax.guide.activity.MingActivity.LEIXING_KEY;
import static zhengyanze.com.aipoemmax.guide.activity.MingActivity.TITLE_KEY;

/**
 * 名句 碎片
 * Created by MrZheng on 2017/7/24.
 */

public class MingJuFragment extends Fragment {
    @BindView(R.id.rv)
    RecyclerView rv;
    Unbinder unbinder;
    ArrayList<LeiXingBean> mLeiBeans;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_leixing, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        LogUtils.e("hehe","onViewCreated() + MingJuFragment");

        mLeiBeans = new ArrayList<>();
        initData();
        initView();
    }

    public void initView() {
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        LeiXingAdapter mLeiAdapter = new LeiXingAdapter(mLeiBeans) {
            @Override
            public void onclickEvent(final LeiViewHolder holder, final int position, final LeiXingBean bean) {
                TypefaceUtil util = new TypefaceUtil(holder.itemView.getContext(), Constant.TTF.TTF_MAIN_TYPE);
                util.setTypeface(holder.tv_leixing,false);
                holder.tv_leixing.setText(bean.getContent());
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(getContext(), MingActivity.class);
                        intent.putExtra(LEIXING_KEY,bean);
                        intent.putExtra(TITLE_KEY,"名句");
                        getActivity().startActivity(intent);
                    }
                });
            }
        };
        rv.setAdapter(mLeiAdapter);
    }

    public void initData() {
        LeiXingBean bean = new LeiXingBean("抒情", Constant.URL.GUSHI_SHUQING);
        LeiXingBean bean2 = new LeiXingBean("四季", Constant.URL.GUSHI_SIJI);
        LeiXingBean bean3 = new LeiXingBean("天气", Constant.URL.GUSHI_TIANQI);
        LeiXingBean bean4 = new LeiXingBean("人物", Constant.URL.GUSHI_RENWU);
        LeiXingBean bean5 = new LeiXingBean("生活", Constant.URL.GUSHI_SHENGHUO);
        LeiXingBean bean6 = new LeiXingBean("节日", Constant.URL.GUSHI_JIERI);
        LeiXingBean bean7 = new LeiXingBean("植物", Constant.URL.GUSHI_ZHIWU);
        LeiXingBean bean8 = new LeiXingBean("食物", Constant.URL.GUSHI_FOOD);
        mLeiBeans.add(bean);
        mLeiBeans.add(bean2);
        mLeiBeans.add(bean3);
        mLeiBeans.add(bean4);
        mLeiBeans.add(bean5);
        mLeiBeans.add(bean6);
        mLeiBeans.add(bean7);
        mLeiBeans.add(bean8);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}

